package com.vol.entity;

/**
 * 全局统一返回结果类
 */
public class Result<T> {
    private boolean status;
    // 返回码
    private Integer code;
    // 返回消息
    private String message;
    // 返回数据
    private T data;
    public Result(){
        this.code = -1;
        this.status = false;
    }
    // 返回数据
    protected static <T> Result<T> build(T data) {
        Result<T> result = new Result<T>();
        if (data != null)
            result.setData(data);
        return result;
    }
    public static <T> Result<T> build(T body, Integer code, String message,boolean status) {
        Result<T> result = build(body);
        result.setCode(code);
        result.setMessage(message);
        result.setStatus(status);
        return result;
    }
    public static <T> Result<T> build(T body, ResultCodeEnum resultCodeEnum, boolean status) {
        Result<T> result = build(body);
        result.setCode(resultCodeEnum.getCode());
        result.setMessage(resultCodeEnum.getMessage());
        result.setStatus(status);
        return result;
    }
    /**
     * 操作成功
     * @param data  baseCategory1List
     * @param <T>
     * @return
     */
    public static<T> Result<T> ok(T data,Integer code,String message){
        Result<T> result = build(data);
        return build(data,code,message,true);
    }
    public Result<T> message(String msg){
        this.setMessage(msg);
        return this;
    }
    public Result<T> code(Integer code){
        this.setCode(code);
        return this;
    }
    public Integer getCode() {
        return code;
    }
    public void setCode(Integer code) {
        this.code = code;
    }
    public String getMessage() {
        return message;
    }
    public void setMessage(String message) {
        this.message = message;
    }
    public T getData() {
        return data;
    }

    public boolean isStatus() {
        return status;
    }

    public void setStatus(boolean status) {
        this.status = status;
    }

    public void setData(T data) {
        this.data = data;
    }
}